home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xmcd-1.4 / PORTING < prev    next >
Encoding:
Text File  |  1995-05-10  |  20.0 KB  |  496 lines

  1. #
  2. # @(#)PORTING    5.3 95/01/27
  3. #
  4. # xmcd  - Motif(tm) CD Audio Player
  5. # cda   - Command-line CD Audio Player
  6. # libdi - CD Audio Player Device Interface Library
  7. #
  8. # by Ti Kan
  9. #
  10.  
  11. Porting Information
  12. -------------------
  13.  
  14.  
  15. INTRODUCTION
  16.  
  17. A truly portable application should compile and run without modification
  18. on different OS and hardware platforms.  Any CD Audio player software,
  19. especially under UNIX, is typically not easily portable.  This is because
  20. of the two following reasons:
  21.  
  22.     1. The CD player software is not merely an application.  It is
  23.        also a device driver of sorts, since it controls the CD-ROM
  24.        drive.  Different OS variants provide different means of
  25.        interfacing with the CD-ROM drives.
  26.  
  27.     2. Although there is an increasing number of CD-ROM drives
  28.        that implement the audio-related commands as documented
  29.        in the SCSI-2 specifications, many non-SCSI-2 conformant
  30.        CD-ROM drives exist, and support audio operations only
  31.        via incompatible vendor-unique commands.  Moreover, there
  32.        are detail differences between "SCSI-2 compliant" drives
  33.        that must be taken into account in order to use them
  34.        effectively.  Finally, there are a number of non-SCSI CD-ROM
  35.        drives that operate via proprietary controller boards.
  36.  
  37. Xmcd and cda strives to be as portable as possible by taking the
  38. following design approach:
  39.  
  40.     1. For xmcd, harness the inherent portability advantages of the
  41.        X Window System, and the increasing popularity of the
  42.        OSF/Motif GUI.  The X Window System gives us device-independent
  43.        graphics and network-extensibility, and Motif is rapidly becoming
  44.        the de facto standard UNIX GUI, and will soon be supported
  45.        on virtually every vendor's port of UNIX as well as UNIX-like
  46.        operating systems.
  47.  
  48.     2. For both xmcd and cda, minimize the use of non-portable
  49.        OS-specific features where possible.
  50.  
  51.     3. Strict adherence to ANSI C standards.
  52.  
  53.     4. Modularize the internals architecture, such that the user
  54.        interface portion, the OS-interface portion, and the CD-ROM
  55.        vendor-unique support portions are each a separate and
  56.        replaceable entity.
  57.  
  58.     5. The OS-specific and device-specific portions are made as small
  59.        and self-contained as possible, so that changes to support
  60.        a new OS or new CD-ROM drive are not scattered about.
  61.  
  62. Currently xmcd/cda already supports a wide array of CD-ROM drives
  63. and OS environments.  You are welcome to help expand that support,
  64. as others have done.  If you would like to add support of additional
  65. CD-ROM devices, port xmcd/cda to run on another OS, or to add other
  66. enhancements to xmcd/cda, the internal architecture overview below
  67. should prove to be beneficial.
  68.  
  69. Xmcd and cda currently contain code that assumes POSIX-compliant
  70. UNIX C library and headers.  Examples of these are:
  71.  
  72.     - Uses "struct dirent" rather than "struct direct"
  73.     - Assumes existence of types such as "uid_t" and "mode_t".
  74.     - etc...
  75.  
  76. Also, cda assumes a System V compatible curses library implementation
  77. for its visual mode support.  Most systems today (even non-SYSV
  78. platforms) supply a compatible library (e.g., ncurses).  If the OS
  79. you're porting to does not support such a library, you can specify
  80. -DNOVISUAL in the cda.d/Imakefile to exclude cda's visual mode
  81. code.
  82.  
  83. Please note that this application is released as free software under
  84. the GNU General License Agreement, which guarantees your right to
  85. modify it for yourself and others (please see the COPYING file for
  86. details).  I do ask, however, that if you add new functionality
  87. or port it to a new platform, please send all changes to me so I
  88. can merge it into the main source code and include it in the next
  89. release.  All proper credit will be given, of course, in the form of
  90. copyright notices in the source file banners.  This avoids diverging
  91. versions and makes your enhancements accessible to more people.
  92.  
  93.  
  94.  
  95. XMCD/CDA ARCHITECTURE
  96.  
  97. Xmcd and cda are divided into three main subsystems, the Application
  98. Code Subsystem, the Device Interface Subsystem and the Utility
  99. Routines Subsystem (These are hereafter referred to as ACS, LIBDI
  100. and LIBUTIL, respectively).
  101.  
  102. The diagram below shows the general xmcd/cda architecture, and
  103. identifies where the various libraries (Motif, Xt, X11, socket,
  104. and the C library) interface with the main xmcd/cda bodies of code.
  105.  
  106.  
  107.             General Internal Architecture
  108.             -----------------------------
  109.  
  110.                               User Interface
  111.   +-------------------------------------------------------------------------+
  112.   |                                                                         |
  113.   |                          Motif (xmcd only)                              |
  114.   |                                                                         |
  115.   |   +----------------+----------------------------------------------------+
  116.   |   |  Xt            |                                                    |
  117.   |   |  Intrinsics    |     Xmcd/cda Application Code Subsystem (ACS)      |
  118.   |   |  (xmcd only)   |                                                    |
  119.   |   | +--------------+             +---------------------------+----------+
  120.   |   | |   X11        |             |                           |          |
  121.   |   | |   (xmcd only)|             |                           |          |
  122.   |   | |              |             |                           |          |
  123.   |   | | +------------+             | Xmcd/cda Device Interface | Utility  |
  124.   |   | | | socket/nsl |             | Subsystem (LIBDI)         | Functions|
  125.   |   | | |            |             |                           | (LIBUTIL)|
  126.   |   | | |   +--------+             |                           |          |
  127.   |   | | |   | curses |             |                           |          |
  128.   |   | | |   | (cda   |             |                           |          |
  129.   |   | | |   |  only) |             |                           |          |
  130.   +---+-+-+---+--------+-------------+---------------------------+----------+
  131.   |                                                                         |
  132.   |                  C Library / System Calls                               |
  133.   |                                                                         |
  134.   +-------------------------------------------------------------------------+
  135.                                 OS Kernel
  136.  
  137.  
  138.  
  139. The ACS is the layer that deals with the user interface.  In xmcd, it
  140. mostly uses Motif for that purpose.  It provides the look-and-feel of the
  141. application and manages all user events.  All calls and other references
  142. to the Motif and X window system are restricted to this module only.
  143.  
  144. The LIBDI module interfaces the application code to the operating
  145. system environment and hardware.
  146.  
  147. The LIBDI can be hardware and OS dependent.  The interface from the
  148. ACS layer to the LIBDI is very high-level, consisting of function
  149. calls like di_play_pause(), di_stop(), di_rew(), di_ff(),
  150. and so on (see libdi.h for the full list).  This gives the LIBDI a lot
  151. of flexibility in how to implement the actual functionalities.
  152. Furthermore, the LIBDI physically resides in a library archive.
  153. Although it is currently linked into xmcd statically, if the need
  154. arises it can be modified to be dynamically bound.
  155.  
  156. LIBDI also relies on service routines in the ACS and LIBUTIL to carry
  157. out its functionality.  The ACS provides those functions that
  158. that cause changes on the user interface (display popup messages,
  159. change widget state, etc.), and LIBUTIL provides general service
  160. routines (perform byte-swapping, BCD to integer conversion, etc).
  161. This layer is hardware platform and OS independent and should require
  162. virtually no modifications to port to other environments.
  163.  
  164. The LIBDI module that is supplied with this distribution implements
  165. two methods of controlling a CD-ROM drive:
  166.  
  167.     0. SCSI pass-through method
  168.     1. SunOS/Linux ioctl method
  169.  
  170. These method can coexist in a given xmcd/cda binary.  The actual
  171. method used is determined at run time via the deviceInterfaceMethod
  172. parameter, which is configured in the LIBDIR/xmcd/config/device.cfg
  173. file.  The entry points into LIBDI is the same regardless of the
  174. method used.  A LIBDI internal jump table (array of di_tbl_t) is
  175. used to select the appropriate method function for each CD audio
  176. operation.
  177.  
  178.  
  179. SCSI PASS-THROUGH METHOD
  180.  
  181. The SCSI pass-through method module supplied is a conglomerate of
  182. a Generic SCSI pass-through sub-module (SCSIPT), an OS Interface
  183. sub-module (OS_XXX), and several Vendor-unique sub-modules (VU_XXX).
  184. These are illustrated in the diagram below.  This method module
  185. implements all the non-user-interface aspects of CD audio
  186. functionality and operates the CD-ROM drive by delivering SCSI
  187. commands directly to the CD-ROM drive via a kernel-supported SCSI
  188. pass-through interface.
  189.  
  190. This distribution supplies several OS_XXX sub-modules, each
  191. supporting a different operating system platform; as well as a
  192. "demo" sub-module that provides a demo environment, but does not
  193. actually operate a real CD-ROM drive (a CD-ROM simulator is invoked
  194. instead, mimicking the behavior of a SCSI-2 CD-ROM drive).  Several
  195. VU_XXX sub-modules for Chinon, Hitachi, NEC, Pioneer, Sony and
  196. Toshiba CD-ROM drives are also supplied.  Only one OS Interface
  197. sub-module can be compiled in at a time (controlled by pre-processor
  198. directives), but multiple vendor-unique sub-modules can coexist.
  199.  
  200. The SCSIPT sub-module contains all the basic non-OS-dependent code
  201. that implements delivering SCSI commands to a CD-ROM drive.  It
  202. relies on the next layer, the OS_XXX sub-module, to actually perform
  203. the SCSI command delivery.  The SCSIPT sub-module "knows" about the
  204. SCSI-2 set of audio-related commands, and sends these down to the
  205. OS_XXX layer.  Which SCSI-2 commands to send are user-configurable
  206. via device-dependent configuration files.  This is important because
  207. many CD-ROM drives support some, but not all of the SCSI-2 audio
  208. commands.  Alternatively, if so configured, the SCSI Pass-through
  209. module can call the VU_XXX sub-module to deliver non-SCSI-2
  210. vendor-unique commands to the CD-ROM drive.
  211.  
  212. All entry points to the OS_XXX module are named in the form of
  213. pthru_xxx().  See below.
  214.  
  215. The most important OS_XXX sub-module entry point is pthru_send(),
  216. which is used by the SCSIPT and VU_XXX sub-modules to deliver SCSI
  217. commands to the drive.  pthru_send() takes a number of arguments
  218. that are used to construct a SCSI CDB, among other things.  The
  219. SCSI CDB is actually allocated and filled in the OS_XXX sub-module,
  220. and delivered using the appropriate SCSI pass-through mechanism.
  221.  
  222.  
  223.  
  224.             SCSI Pass-through Method Detail
  225.             -------------------------------
  226.  
  227.                               User Interface
  228.   +-------------------------------------------------------------------------+
  229.   |                                                                         |
  230.   |                          Motif (xmcd only)                              |
  231.   |                                                                         |
  232.   |   +----------------+--------------------------------------------+-------+
  233.   |   |  Xt            |                                            |       |
  234.   |   |  Intrinsics    |  Xmcd/cda Application Code Subsystem (ACS) | Util  |
  235.   |   |  (xmcd only)   |                                            | Func  |
  236.   |   | +--------------+     +--------------------------------------+ (LIB- |
  237.   |   | | X11          |     |                                      |  UTIL)|
  238.   |   | | (xmcd only)  |     |     Generic SCSI Pass-through        |       |
  239.   |   | |              |     |     Module (SCSIPT)                  |       |
  240.   |   | | +------------+     |                                      |       |
  241.   |   | | | socket/nsl |     |   +-----------------+----------------+       |
  242.   |   | | |            |     |   |                 |                |       |
  243.   |   | | |   +--------+     |   | OS Interface    | CD-ROM         |       |
  244.   |   | | |   | curses |     |   | Module          | Vendor-unique  |       |
  245.   |   | | |   | (cda   |     |   | (OS_XXX)        | Modules        |       |
  246.   |   | | |   |  only) |     |   |                 | (VU_XXX)       |       |
  247.   +---+-+-+---+--------+-----+---+-----------------+----------------+-------+
  248.   |                                                                         |
  249.   |                  C Library / System Calls                               |
  250.   |                                                                         |
  251.   +-------------------------------------------------------------------------+
  252.                                 OS Kernel
  253.  
  254.  
  255.  
  256. LINUX IOCTL METHOD
  257.  
  258. The SunOS/Linux ioctl method is intended primarily for use on Linux
  259. platforms which are equipped with non-SCSI CD-ROM drives operating
  260. via a proprietary interface card.  Although this method will also work
  261. with many SCSI CD-ROM drives on the Linux, SunOS 4.1.x (Solaris 1.x)
  262. and SunOS 5.x (Solaris 2.x) platforms, it offers less features than
  263. the SCSI pass-through method and is thus not recommended for SCSI drives.
  264.  
  265. The SunOS/Linux ioctl method can also serve as a reference when porting
  266. xmcd/cda to an OS platform that does not support a SCSI pass-through
  267. interface.
  268.  
  269. The SunOS/Linux ioctl method module has similar high-level operating
  270. code as the SCSI pass-through method, except it is monolithic and does
  271. not have sub-modules.  It operates the CD-ROM audio functions via ioctl
  272. interfaces to the SunOS and Linux CD-ROM driver.
  273.  
  274.  
  275.             SunOS/Linux Ioctl Method Detail
  276.             -------------------------------
  277.  
  278.                               User Interface
  279.   +-------------------------------------------------------------------------+
  280.   |                                                                         |
  281.   |                          Motif (xmcd only)                              |
  282.   |                                                                         |
  283.   |   +----------------+----------------------------------------------------+
  284.   |   |  Xt            |                                                    |
  285.   |   |  Intrinsics    |     Xmcd/cda Application Code Subsystem (ACS)      |
  286.   |   |  (xmcd only)   |                                                    |
  287.   |   | +--------------+             +---------------------------+----------+
  288.   |   | | X11          |             |                           |          |
  289.   |   | | (xmcd only)  |             |                           |          |
  290.   |   | |              |             |                           |          |
  291.   |   | | +------------+             | SunOS/Linux Ioctl Method  | Utility  |
  292.   |   | | | socket/nsl |             | (SLIOC)                   | Functions|
  293.   |   | | |            |             |                           | (LIBUTIL)|
  294.   |   | | |   +--------+             |                           |          |
  295.   |   | | |   | curses |             |                           |          |
  296.   |   | | |   | (cda   |             |                           |          |
  297.   |   | | |   |  only) |             |                           |          |
  298.   +---+-+-+---+--------+-------------+---------------------------+----------+
  299.   |                                                                         |
  300.   |                  C Library / System Calls                               |
  301.   |                                                                         |
  302.   +-------------------------------------------------------------------------+
  303.                                 OS Kernel
  304.  
  305.  
  306.  
  307. XMCD/CDA SOURCE CODE FILES
  308.  
  309. The following is a list of the files in the xmcd/cda source code
  310. distribution and the category they fall under:
  311.  
  312. General Release files:
  313.     BUGS
  314.     CHANGES
  315.     COPYING
  316.     INSTALL
  317.     PORTING
  318.     README
  319.     Imakefile
  320.     Makefile.std
  321.     make.inc
  322.     makedgux.inc
  323.  
  324. LIBUTIL and other common files:
  325.     common.d/Imakefile
  326.     common.d/Makefile.std
  327.     common.d/appenv.h
  328.     common.d/patchlevel.h
  329.     common.d/util.c
  330.     common.d/util.h
  331.  
  332. LIBDI files:
  333.     libdi.d/Imakefile
  334.     libdi.d/Makefile.std
  335.     libdi.d/libdi.c
  336.     libdi.d/libdi.h
  337.     libdi.d/configure.sh
  338.     libdi.d/common.cfg
  339.     libdi.d/device.cfg
  340.     libdi.d/cfgtbl/XXX
  341.  
  342.     SCSI pass-through method files:
  343.         libdi.d/scsipt.c
  344.         libdi.d/scsipt.h
  345.         libdi.d/os_XXX.c
  346.         libdi.d/os_XXX.h
  347.         libdi.d/vu_XXX.c
  348.         libdi.d/vu_XXX.h
  349.  
  350.     SunOS/Linux ioctl method files:
  351.         libdi.d/lxioc.c
  352.         libdi.d/lxioc.h
  353.  
  354. ACS for cda:
  355.     cda.d/Imakefile
  356.     cda.d/Makefile.std
  357.     cda.d/cda.c
  358.     cda.d/cda.h
  359.     cda.d/visual.c
  360.     cda.d/visual.h
  361.     cda.d/cda.man
  362.  
  363. ACS for xmcd:
  364.     xmcd.d/Imakefile
  365.     xmcd.d/Makefile.std
  366.     xmcd.d/XKeysymDB
  367.     xmcd.d/XMcd.ad
  368.     xmcd.d/cdfunc.c
  369.     xmcd.d/cdfunc.h
  370.     xmcd.d/dbprog.c
  371.     xmcd.d/dbprog.h
  372.     xmcd.d/geom.c
  373.     xmcd.d/geom.h
  374.     xmcd.d/help.c
  375.     xmcd.d/help.h
  376.     xmcd.d/hotkey.c
  377.     xmcd.d/hotkey.h
  378.     xmcd.d/main.c
  379.     xmcd.d/resource.h
  380.     xmcd.d/widget.c
  381.     xmcd.d/widget.h
  382.     xmcd.d/xmcd.h
  383.     xmcd.d/xmcd.man
  384.     xmcd.d/bitmaps/*
  385.     xmcd.d/hlpfiles/*
  386.  
  387. Miscellaneous utilities and files:
  388.     misc.d/BINLIST
  389.     misc.d/SRCLIST
  390.     misc.d/makerel.sh
  391.     misc.d/makeshar.sh
  392.     misc.d/makesrc.sh
  393.     misc.d/demo.db
  394.  
  395. Workman-to-Xmcd CD database converter utility:
  396.     wm2xmcd.d/Imakefile
  397.     wm2xmcd.d/Makefile.std
  398.     wm2xmcd.d/wm2xmcd.c
  399.     wm2xmcd.d/wm2xmcd.man
  400.  
  401.  
  402.  
  403. PORTING HINTS
  404.  
  405. To port xmcd/cda to a different OS, two alternatives can be
  406. considered:
  407.  
  408. 1. Use the existing SCSI pass-through method, but write a new
  409.    OS_XXX sub-module.
  410. 2. Write a whole new method module.
  411.  
  412. The first choice is the obvious answer if the target OS supports a
  413. SCSI pass-through interface.  This choice is also quite easy to
  414. implement, as the OS_XXX sub-module is typically fairly small
  415. and self-contained.  The existing OS_XXX sub-modules can be used
  416. as a reference when writing a new one.  In the current implementation,
  417. each SCSI pass-through OS_XXX sub-module must contains these four
  418. routines:
  419.  
  420.     pthru_send()
  421.     pthru_open()
  422.     pthru_close()
  423.     pthru_vers()
  424.  
  425. The second choice is feasible if the platform does not supply a
  426. SCSI pass-through mechanism, or if non-SCSI drives are to be used.
  427. If this is the approach taken, the SunOS/Linux ioctl method module
  428. can be used as a reference, and much of its code can be copied,
  429. modified and re-used.
  430.  
  431. If you are writing an SCSI pass-through OS_XXX sub-module, keep in
  432. mind that you will need to deal with any special DMA address
  433. alignment limitations present in your OS and/or hardware.  The I/O
  434. data buffers allocated within the existing SCSI pass-through method
  435. are guaranteed to be 32-bit word-aligned, but if your OS/hardware
  436. has different requirements (such as page-alignment) then you will
  437. need to deal with this in the OS interface sub-module.
  438.  
  439. For maximum portability, please use the bswapxx() and lswapxx()
  440. routines provided in util.c (#include "common.d/util.h") to
  441. perform byte swapping, whenever multi-byte quantities (that must
  442. be interpreted as a value) are being transferred between the CD-ROM
  443. drive and the host.  This is necessary because multi-byte
  444. quantities in SCSI commands and data is in general big-endian,
  445. but xmcd/cda is designed to run on host CPUs that are big-endian
  446. or little-endian.  The swap routines should be used regarless of
  447. whether your main CPU endianess matches that of the SCSI device.
  448. Whether swapping actually takes place is controlled via the
  449. _BYTE_ORDER_ #define (see common.d/appenv.h).
  450.  
  451. There are also some minor OS-specific code you need to add in
  452. configure.sh.  This is mainly to set up the correct default device
  453. node path name and mailer program.
  454.  
  455.  
  456.  
  457. ADDING SUPPORT OF NON-SCSI-2 CD-ROMS
  458.  
  459. To support additional SCSI (not SCSI-2) CD-ROM drives via vendor-
  460. unique pass-through commands, you will need to add a VU_XXX sub-module
  461. to the SCSI pass-through method.  Each VU_XXX sub-module can implement
  462. some or all of the following routines (where xx is the name of the
  463. VU_XXX module):
  464.  
  465.     xx_playaudio()
  466.     xx_pause_resume()
  467.     xx_start_stop()
  468.     xx_get_playstatus()
  469.     xx_volume()
  470.     xx_route()
  471.     xx_mute()
  472.     xx_get_toc()
  473.     xx_eject()
  474.     xx_start()
  475.     xx_halt()
  476.  
  477. These routines, if implemented, is then registered in the xx_init()
  478. routine by filling in the appropriate vu_tbl_t array entry (see
  479. scsipt.[ch] and the existing VU_XXX sub-modules for examples).
  480.  
  481. Depending upon the operating mode of xmcd, vendor-unique functionality
  482. is invoked from the scsipt.c module via the vu_tbl_t jump table.
  483.  
  484. You will also need to add a vendor-unique configuration file entry 
  485. to the libdi.d/cfgtbl subdirectory.
  486.  
  487.  
  488.  
  489. QUESTIONS?
  490.  
  491. If you are working on enhancing xmcd/cda and need information, help
  492. or advice, please send e-mail to me at "ti@amb.org".  Likewise,
  493. suggestions are also very welcome.
  494.  
  495.  
  496.